package com.hyz.reggie.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyz.reggie.pojo.Orders;
import com.hyz.reggie.pojo.R;
import com.hyz.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     *
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {
        log.info("订单数据：{}", orders);
        orderService.submit(orders);
        return R.success("下单成功");
    }

    @GetMapping("/page")
    public R getPage(Integer page, Integer pageSize, Long number, String beginTime, String endTime) {
        IPage<Orders> iPage = orderService.getPage(page, pageSize, number, beginTime, endTime);
        return R.success(iPage);
    }

    @PutMapping
    public R sendOrders(@RequestBody Orders orders) {
        orderService.sendOrders(orders);
        return R.success("开始配送~");
    }

    @GetMapping("/userPage")
    public R getUserPage(Integer page, Integer pageSize) {
        IPage<Orders> iPage = orderService.getUserPage(page, pageSize);
        return R.success(iPage);
    }

    @PostMapping("/again")
    public R moreAgain(@RequestBody Orders orders) {
        orderService.moreAgain(orders);
        return R.success("下单成功~");
    }
}